//电子卡列表
var server = require('../../utils/server');
var common = require('../../utils/common');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curTab: 1,
    cardLists: [],
    disCardLists: [],
   curQrcodeImg: "",
    isShowCodeImg: false,
    curQrcode: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getYcCards();
  },
  getYcCards() {
    server.postJSON(common.basePath + 'cardVoucher/list', '', res => {
      if (res.data.errno == '0') {
      var cardLists = res.data.data.filter((item, index) => {
        return item.error == "";
      })
      this.setData({
        cardLists: cardLists
      })
      var disCardLists = res.data.data.filter((item, index) => {
        return item.error != "";
      })
      console.log(disCardLists)
      this.setData({
        disCardLists: disCardLists
      })
      }else{
        common.showErrorToast(res.data.errmsg);
      }
    })
  },
  goToDetail(e) {
    wx.navigateTo({
      url: 'ycCardPayDetail?cardid=' + e.currentTarget.dataset.id,
    })
  },
  goToBindCard() {
    wx.navigateTo({
      url: 'bindYcCard?type=0',
    })
  },
  switchTab(e) {
    this.setData({
      curTab: e.currentTarget.dataset.id
    })
  },
  showQrcode(e) {
    var qrcode = e.currentTarget.dataset.qrcode;
    if(qrcode!=''){
      this.setData({
        curQrcodeImg: common.basePath + 'membercard/barcode/mobile/' + qrcode,
        isShowCodeImg: true,
        curQrcode: qrcode
      })
    }
  },
  hideCodeImg() {
    this.setData({
      isShowCodeImg: false
    })
  }
})